export {};
//获取用户列表 远程的方法
interface User {
  username: string;
  password: string;
}

interface Person {
  name: string;
  age: number;
}

function getList(url: string): Array<User> {
  if (url === "/user/list") {
    //模拟访问java接口，获取数据库中的数据
    let users: Array<User> = [
      { username: "admin", password: "123546" },
      { username: "admin", password: "123546" },
    ];

    return users;
  }
  return [];
}

// function getList<T>(url: string): Array<User> {
//   if (url === "/user/list") {
//     //模拟访问java接口，获取数据库中的数据
//     let users: Array<User> = [
//       { username: "admin", password: "123546" },
//       { username: "admin", password: "123546" },
//     ];

//     return users;
//   }
//   return [];
// }

let userList: Array<User> = getList("/user/list");

userList.forEach((user: User) => {
  // document.createElement("table")
  console.log("user--循环生成表格  doc", user);
});

// 在接口中使用泛型
interface CommonResult<T> {
  code: number;
  data: T;
}

let res1: CommonResult<User> = {
  code: 1,
  data: { username: "admin", password: "123546" },
};

let res2: CommonResult<Person> = {
  code: 1,
  data: { name: "zhangsan", age: 18 },
};
